#http://mail.python.org/pipermail/python-list/2000-April/030560.html
#import psyco
#psyco.profile()
def succ(choice, n, k) :
    # Returns the 'next' increasing k-element subset of
    # {0 ... n-1} after choice. It does so by working from
    # the end of the list, trying to increment elements.
    # Once it finds one it can increment, it then works
    # back towards the end filling in the remaining
    # values.
    index = k - 1
    while index >= 0:
        choice[index] = choice[index] + 1
        if choice[index] <= n - k + index:
            break
        index = index - 1
    else:
        return 0
    while index < k - 1 :
        choice[index + 1] = choice[index] + 1
        index = index + 1
    return 1

def choices(n, k) :
    # Returns a list consisting of all k-element (ordered)
    # subsets of {0 ... n-1}.
    result = []
    if k > n :
        return result

    current = range(k)
    while 1 :
        pass#result.append(current[:])
        if not succ(current, n, k) :
            break
    return result

for elem in choices(52, 5):
    pass#print elem
